from multiprocessing import Process,Queue
from os import getpid
from random import randint
from time import time, sleep


def add1(mQueue):
    print('进程号[%d].' % getpid())
    mQueue.put(30)
def add2(mQueue):
    print('进程号[%d].' % getpid())
    mQueue.put(20)
def main():
    start = time()
    mQueue = Queue()
    p1 = Process(target=add1, args=(mQueue,))
    p1.start()
    p2 = Process(target=add2, args=(mQueue,))
    p2.start()
    p1.join()
    p2.join()
    total = 0
    while not mQueue.empty():
        total = total + mQueue.get()
    print(total)
    end = time()
    print('总共耗费了%.2f秒.' % (end - start))

if __name__ == '__main__':
    main()